import sys
import os

# 添加项目根目录到路径
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, project_root)

from src.data_collector.youtube_subtitle_fetcher import YouTubeSubtitleFetcher
import logging

# 设置日志
logging.basicConfig(level=logging.INFO)

def test_fetcher(video_id):
    """
    测试YouTube字幕获取器
    """
    print(f"正在测试获取视频 {video_id} 的字幕...")
    
    fetcher = YouTubeSubtitleFetcher(output_dir="output/subtitles")
    
    # 测试获取字幕列表
    print("测试获取字幕列表...")
    langs = fetcher.get_available_languages(video_id)
    print(f"支持的语言: {langs}")
    
    # 测试下载英文字幕
    print("测试下载英文字幕...")
    result = fetcher.download_subtitles(video_id, "en")
    print(f"下载结果: {result}")
    
    # 如果英语字幕下载失败，尝试其他语言
    if not result and langs:
        print(f"尝试下载其他语言字幕: {langs[0]}")
        result = fetcher.download_subtitles(video_id, langs[0])
        print(f"下载结果: {result}")

if __name__ == "__main__":
    test_fetcher("Q0GPGvMu77w")